package com.hr.utils;

import org.apache.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName ResultInfo
 * @Description TODO
 * @Author hkp
 **/

public class ResultInfo extends HashMap<String,Object> {
    public ResultInfo() {
        put("msg","success");
        put("code", HttpStatus.SC_OK);
    }
    //链式
    public ResultInfo put(String key,Object value){
        super.put(key,value);
        return this;
    }
    //成功返回格式 重载
    public static ResultInfo success(){
        return new ResultInfo();
    }

    public static ResultInfo success(String msg){
        return new ResultInfo().put("msg",msg);
    }
    public static ResultInfo success(Map<String,Object> map){
        ResultInfo r = new ResultInfo();
        r.putAll(map);
        return r;
    }

    //失败返回格式
    public static ResultInfo fail(){
        return fail(HttpStatus.SC_INTERNAL_SERVER_ERROR,"出现错误");
    }

    public static ResultInfo fail(String msg){
        return fail(HttpStatus.SC_INTERNAL_SERVER_ERROR,msg);
    }

    public static ResultInfo fail(int code,String msg){
        return new ResultInfo().put("msg",msg).put("code",code);
    }
}

